#include <bits/stdc++.h>
#define VNAME(name) (#name)
#define F_(n) cout << fixed << setprecision(n)
#define gc() (ibo_ == ied_ ? (ied_ = buf + fread(ibo_ = buf, 1, 1 << 20, stdin), ibo_ == ied_ ? EOF : *ibo_++) : *ibo_++)
#define read() ({ int x = 0, f = 1; char c = gc(); while(c < '0' || c > '9') { if (c == '-') f = -1; c = gc();} while(c >= '0' && c <= '9') x = x * 10 + (c & 15), c = gc(); f * x; })
char buf[1 << 20], puf[1 << 20], *_p_ = puf, *ibo_, *ied_;
#define pr(x) (_p_ - puf == 1 << 20 ? (fwrite(puf, 1, 1 << 20, stdout), _p_ = puf) : 0, *_p_++ = x)
int print(long long x) { return x <= 9 ? pr(x + '0') : (print(x / 10), pr(x % 10 + '0')); }
#ifndef ONLINE_JUDGE
    #define debug(x) {auto debugx = x; std::cout << " (" << VNAME(x) << ": " << debugx << ") ";}
    #define debugln(x) {auto debugx = x; std::cout << " (" << VNAME(x) << ": " << debugx << ") " << std::endl;}
#else
    #define debug(x) {(x);}
    #define debugln(x) {(x);}
	#define endl '\n'
#endif
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
bool _OJ_Flag = true;
static int ____________________________________________________ = []() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    return 0;
}();//*/
unordered_map<int, int> M;
int solve(vector<PII> &arr, int n, int m) {
    int cm = M.size();
    if (cm > m) return -1;
    else if (cm == m) { nth_element(arr.begin(), arr.begin(), arr.end(), greater<PII>()); return arr.front().first;}
    priority_queue<int, vector<int>, less<int> > q;
    for (int i = cm - m; ~i; -- i) {
        nth_element(arr.begin(), arr.begin() + i, arr.end(), greater<PII>());
        q.push();
    }
    return 0;
}
signed main() {
    #ifndef ONLINE_JUDGE
		_OJ_Flag = false; //freopen("C:\\Users\\lenovo\\Desktop\\in.in", "r", stdin);
	#endif
    int t = 1;
    //cin >> t;
    while (t --) {
        int n, m;
        cin >> n >> m;
        vector<int> arr(n);
        for (int i = 0; i < n; ++ i) cin >> arr[i], M[arr[i]] ++;
        vector<PII> w;
        for (auto i : M) w.push_back({i.second, i.first});
        cout << solve(w, n, m);
        //debug(solve(n));
    }
    #ifndef ONLINE_JUDGE
        cout << endl;
		system("pause");
	#endif
    return 0;
}